//
//  UIImage+UBRAddtions.m
//  UBR
//
//  Created by 刘冲 on 2020/4/21.
//  Copyright © 2020 Universal Studios. All rights reserved.
//

#import "UIImage+HSAddtions.h"

@implementation UIImage (HSAddtions)

// 根据颜色生成UIImage
+ (UIImage*)imageWithColor:(UIColor*)color{
    
    CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    // 开始画图的上下文
    UIGraphicsBeginImageContext(rect.size);
    
    // 设置背景颜色
    [color set];
    // 设置填充区域
    UIRectFill(CGRectMake(0, 0, rect.size.width, rect.size.height));
    
    // 返回UIImage
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    // 结束上下文
    UIGraphicsEndImageContext();
    return image;
}

- (UIImage *)toPNG {
    NSData *imageData = UIImagePNGRepresentation(self);
    UIImage *pngImage = [UIImage imageWithData:imageData];
    return pngImage;
}
@end
